import os

from Extend.NoSql import Heart


class GrandClass:
    def __init__(self):
        Heart.setMeHeart(self.__class__.__name__, False)
        Heart.setMeStat(self.__class__.__name__, False)

    def start(self):
        Heart.setPid(self.__class__.__name__, os.getpid())
        if Heart.getMeStat(self.__class__.__name__):
            return 'Server Is Run!'
        Heart.setMeHeart(self.__class__.__name__, True)
        try:
            self.startMonitors()
        except Exception as err:
            Heart.setMeStat(self.__class__.__name__, False)
            return

    def stop(self):
        Heart.setMeHeart(self.__class__.__name__, False)

    def isRun(self):
        return Heart.getMeStat(self.__class__.__name__)

    def startMonitors(self):
        Heart.setMeStat(self.__class__.__name__, True)
        if Heart.getMeHeart(self.__class__.__name__, ) is False:
            # print('检测到关闭')
            Heart.setMeStat(self.__class__.__name__, False)
            return
